//签名信息
var bip39 = require('bip39')
var bitcoin = require('bitcoinjs-lib')
var ecc = require('tiny-secp256k1')
var util = require('ethereumjs-util')
var bs58check = require('bs58check')
const secp256k1 = require('secp256k1')

var privateKey = "cSkTBuc1aSdzcPE4AXcQHpWD6uedRd3t6xjeWLvjP6LeDZUBPkGt"




let s = "\x18Bitcoin Signed Message:\n"

let msgHash = bitcoin.crypto.hash256(Buffer.from(s+"123456"))
console.log(msgHash.toString('hex'))
var decoded = bs58check.decode(privateKey)
var decoded1 = decoded.slice(1,-1)
console.log(decoded.toString('hex'))
console.log(decoded.length)

var sig = ecc.sign(msgHash, decoded1)
var sa = sig.toString('hex')
sa ="27" + sa;
//console.log(Buffer.from(sa,'hex'))
var t = Buffer.from(sa,'hex');
//var sig1 = secp256k1.sign(msgHash,decoded.slice(1,-1))
console.log(t.toString('base64'))
//console.log(sig1.signature.toString('hex'))
//40091923965f23bfd5e10c339089d3c2b60894bfbdd0629b71137a29310f52074ea39825282db4534efc2ef60825239a89c0c72ff2f50ce8822c8c531c899dcb

//<Buffer 1b 59 cf 03 50 73 58 ed e5 f4 f0 79 c1 58 b9 37 a1 fd 14 f1 a3 24 98 a7
//e4 e2 ae a2 fd a2 88 68>
//<Buffer ef 9a 33 fe fb 18 d1 47 e2 9d 41 8b 2c 31 6a a9 69 1e dd 39 0f 6b 36 c6
//aa 88 21 65 af 7d 79 a4 e4 01>
//34
//{ signature: <Buffer 40 09 19 23 96 5f 23 bf d5 e1 0c 33 90 89 d3 c2 b6 08 94 bf
// bd d0 62 9b 71 13 7a 29 31 0f 52 07 4e a3 98 25 28 2d b4 53 4e fc 2e f6 08 25 2
//3 9a 89 c0 ... >,
//  recovery: 1 }//

//ef9a33fefb18d147e29d418b2c316aa9691edd390f6b36c6aa882165af7d79a4e401
//128//40091923965f23bfd5e10c339089d3c2b60894bfbdd0629b71137a29310f52074ea39825282db4534efc2ef60825239a89c0c72ff2f50ce8822c8c531c899dcb